package com.twang.stock.task;

import com.twang.stock.task.old.GaiNianZiJingPaiHangTask;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;

import java.util.List;

public class SSQService {
    public static void main(String[] args) throws Exception {
        // HttpClient 超时配置
        RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD)
                .setConnectionRequestTimeout(6000).setConnectTimeout(6000).build();
        CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig).build();
        // 发送请求，并执行
        String htmlForStock = GaiNianZiJingPaiHangTask.getHtmlStrByUrl("http://kaijiang.zhcw.com/zhcw/html/ssq/list.html", httpClient, GaiNianZiJingPaiHangTask.COOKIE, GaiNianZiJingPaiHangTask.USER_AGENT);
        // 网页内容解析
        System.out.println("该网页存在,正在解析:{}" + htmlForStock);
        Document doc = Jsoup.parse(htmlForStock);
        // 第一个数组：title
        Elements listTrs = doc.select("table[class=wqhgt]").get(0).select("tr");
        int i=1;
        for (int j =listTrs.size()-3; j>=0; j--) {
            Elements tds = listTrs.get(j + 1).select("td");
            StringBuffer bf = new StringBuffer("");
         //  bf.append("日期："+tds.get(0).text()+"  ");
            List<Node> nodes=tds.get(2).childNodes();
            System.out.print(i);
            bf.append("   A组:").append(nodes.get(1).childNodes().get(0));
            bf.append("   ").append(nodes.get(3).childNodes().get(0));
            bf.append("   ").append(nodes.get(5).childNodes().get(0));
            bf.append("   ").append(nodes.get(7).childNodes().get(0));
            bf.append("   ").append(nodes.get(9).childNodes().get(0));
            bf.append("   ").append(nodes.get(11).childNodes().get(0));
            bf.append("   B组:").append(nodes.get(13).childNodes().get(0));
            System.out.println( bf.toString());
            i++;
        }
    }
}
